package dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class BaseDao<T> {

	private SessionFactory sessionFactory;

	public Session getSession() {
		return this.sessionFactory.getCurrentSession();
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	public List<T> findEntityByHQL(String hql, Object... objects) {
		 Query q  = sessionFactory.getCurrentSession().createQuery(hql);
		 for(int i = 0; i < objects.length; i++){
			 q.setParameter(i, objects[i]);
		 }
		return q.list();
	}
	
}
